home *** CD-ROM | disk | FTP | other *** search
-
- /* This is a preprocessor to the _ModalDialog call
- ModalDialog(filter:ProcPtr; VAR itemHit:integer):integer;
-
- It will check for a nil pointer, and if so replace it will a
- pointer to my routine.
-
- */
- #include <strings.h>
-
- #define SETUPA4() _A4SET(1)
- #define INITA4() _A4SET(0)
- #define maxStrings 30
-
- extern char *modalDTrap;
- Boolean seenUpdate, hasEditFields;
- char letterArray[maxStrings]; /*array of the first chars of the first maxStrings buttons*/
- ProcPtr oldFilter;
-
- /* ================================================================ */
- void DoAbout()
- /* ---------------------------------------------------------------- */
- {
- #define textBase 10
-
- int oldFont, oldSize, counter, myTicks;
- GrafPtr curPort;
- Rect theRect;
- long dummy, curTicks;
- EventRecord theEvent;
-
- GetPort(&curPort);
- oldFont = curPort->txFont;
- oldSize = curPort->txSize;
- TextFont(1); /* geneva */
- TextSize(9);
-
- myTicks = 5;
- for (counter=curPort->portRect.left;
- counter<=curPort->portRect.right+10;
- counter+=5)
- {
- SetRect(&theRect, curPort->portRect.left, 0, curPort->portRect.right+10,textBase+2);
- EraseRect(&theRect);
- MoveTo(counter, textBase);
- DrawString("\pAlerter by Leonard Rosenthol");
- curTicks = TickCount();
- while (TickCount()<curTicks+myTicks);
- if (EventAvail(keyDownMask+mDownMask, &theEvent)) { myTicks = 1; } /* set it to like no delay */
- }
- TextFont(oldFont);
- TextSize(oldSize);
- }
-
- /* ================================================================ */
- pascal Boolean callOldFilter (dPtr, theEvent, itemHit)
- register DialogPtr dPtr;
- register EventRecord * theEvent;
- register int *itemHit;
- /* ---------------------------------------------------------------- */
- {
- extern ProcPtr oldFilter;
-
- return(CallPascalB(dPtr, theEvent, itemHit, oldFilter));
- }
-
- /* ================================================================ */
- pascal Boolean alertFilter (dPtr, theEvent, itemHit)
- register DialogPtr dPtr;
- register EventRecord * theEvent;
- register int *itemHit;
- /* ---------------------------------------------------------------- */
- {
- register int Key, counter = 1;
- GrafPtr oldPort;
- Boolean retVal, done = FALSE;
-
- asm {
- movem.l a1-a5/d0-d7,-(sp) /* save the regs */
- };
- SETUPA4();
-
- retVal = FALSE;
- if (seenUpdate)
- {
- hasEditFields = FALSE; /* init it going into WalkList */
- WalkList(dPtr);
- }
-
- if (seenUpdate && isoptionkey())
- {
- GetPort(&oldPort);
- SetPort(dPtr);
- DoAbout();
- SetPort(oldPort);
- seenUpdate = FALSE;
- }
-
- if (theEvent->what == updateEvt)
- seenUpdate = TRUE;
-
- if (theEvent->what != keyDown)
- {
- if (oldFilter==0L)
- return (false);
- else
- return(callOldFilter(dPtr, theEvent, itemHit));
- }
-
- Key = (unsigned char) theEvent->message;
-
- if (((hasEditFields) && (theEvent->modifiers & cmdKey)) ||
- (!hasEditFields))
- {
- do{
- if ( (Key==letterArray[counter]) || (Key==letterArray[counter]-0x20))
- {
- *itemHit = counter;
- FlashItem(dPtr, counter);
- retVal = TRUE;
- done = TRUE;
- }
- counter++;
- } while ((!done) && (counter<maxStrings));
- }
-
- if ((Key=='\r') || (Key=='\003'))
- {
- *itemHit = ((DialogPeek)dPtr)->aDefItem; /*get the default item*/
- FlashItem(dPtr, *itemHit);
- retVal = TRUE;
- }
-
- if (!retVal) /* found nothing else to do */
- {
- if (oldFilter==0L)
- return (false);
- else
- return(callOldFilter(dPtr, theEvent, itemHit));
- }
-
- asm {
- Movem.l (sp)+,a1-a5/d0-d7 /* restore all regs */
- };
- return (retVal);
-
- }
-
-
- pascal int myModalDialog(theFilter, theID)
- int *theID;
- ProcPtr theFilter;
- {
- asm {
- movem.l a1-a5/d0-d7,-(sp) /* save the regs */
- };
-
- SETUPA4();
- seenUpdate = FALSE;
-
- if (theFilter==0L)
- {
- theFilter=(ProcPtr)alertFilter;
- oldFilter = 0L; /* set it to nil SPECIFICALLY */
- }
- else
- {
- oldFilter = (ProcPtr)theFilter; /* set it to the old filter */
- theFilter=(ProcPtr)alertFilter;
- };
-
- asm {
- move.l modalDTrap,a0
- Movem.l (sp)+,a1-a5/d0-d7 /* restore all regs */
- unlk a6
- jmp(a0) /* Do the load */
- };
- };
-